package com.ctgu.chatapp.model.Dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy.REPLACE
import androidx.room.Query
import com.ctgu.chatapp.model.Retrofit.Pojo.Friend
import com.ctgu.chatapp.model.pojo.FriendShip
import com.ctgu.chatapp.showPojo.Contact
import com.ctgu.chatapp.showPojo.FriendListByGroup
import kotlinx.coroutines.flow.Flow

@Dao
interface FriendDao {
    @Insert(onConflict = REPLACE)
    suspend fun addFriend(friendShipList: List<FriendShip>)

    @Insert
    suspend fun addFriendOne(friendShip: FriendShip)

    @Query("select Information.chatID,Information.nickName,Information.motto,Information.profile from FriendShip left join Information on FriendShip.touId = Information.chatID where FriendShip.uid = :chatID")
    fun getAllFriend(chatID: Long): Flow<List<Contact>>

    @Query("select type from FriendShip where uid = :selfID group by type order by type")
    fun getGroup(selfID: Long): Flow<List<FriendListByGroup>>

    @Query("select Information.chatID,Information.nickName,Information.motto,Information.profile from FriendShip left join Information on FriendShip.touId = Information.chatID where FriendShip.uid = :chatID and FriendShip.type = :groupName")
    fun getGroupFriend(chatID: Long, groupName: String): List<Contact>

    @Query("select Information.chatID,Information.changeTime from friendship left join Information on Information.chatID == friendship.touId where friendship.uid = :uid ")
    fun getAllFriendList(uid: Long): List<Friend>

    @Query("select * from friendship where uid  = :uid")
    fun getAllFriendChatID(uid: Long): List<FriendShip>

    @Delete
    fun deleteFriend(friendShipList: List<FriendShip>)
}